package com;

/**
 * 正则表达式
 */
public class RegexMain {
    public static void main(String[] args) {
        String data = "KissWithYou\\123142~(";
        String regex = "[\\\\0-9a-zA-Z~`!@#$%^&*()_\\-\\+=/*|\\:;'<,>\\.?{}\\[\\]]+";
        if (match(data, regex)) {
            System.out.println("符合规则");
        }
        // 不符合规则
        else {
            System.out.println("不符合规则");
        }
    }

    public static boolean match(String data, String regex) {
        return !isEmpty(data) && data.matches(regex);
    }

    private static boolean isEmpty(String data) {
        return data == null || data.length() == 0;
    }
}
